package com.ruoyi.project.infoprojectdepartment.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.project.infoprojectdepartment.domain.InfoProjectDepartment;
import com.ruoyi.project.infoprojectdepartment.mapper.InfoProjectDepartmentMapper;
import com.ruoyi.project.infoprojectdepartment.service.IInfoProjectDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 协同科室项目关联Service业务层处理
 *
 * @author ruoyi
 * @date 2022-06-29
 */
@Service
public class InfoProjectDepartmentServiceImpl implements IInfoProjectDepartmentService
{
    @Autowired
    private InfoProjectDepartmentMapper infoProjectDepartmentMapper;

    /**
     * 查询协同科室项目关联
     *
     * @param id 协同科室项目关联主键
     * @return 协同科室项目关联
     */
    @Override
    public InfoProjectDepartment selectInfoProjectDepartmentById(Long id)
    {
        return infoProjectDepartmentMapper.selectInfoProjectDepartmentById(id);
    }

    /**
     * 查询协同科室项目关联列表
     *
     * @param infoProjectDepartment 协同科室项目关联
     * @return 协同科室项目关联
     */
    @Override
    public List<InfoProjectDepartment> selectInfoProjectDepartmentList(InfoProjectDepartment infoProjectDepartment)
    {
        return infoProjectDepartmentMapper.selectInfoProjectDepartmentList(infoProjectDepartment);
    }

    /**
     * 新增协同科室项目关联
     *
     * @param infoProjectDepartment 协同科室项目关联
     * @return 结果
     */
    @Override
    public int insertInfoProjectDepartment(InfoProjectDepartment infoProjectDepartment)
    {
        infoProjectDepartment.setCreateTime(DateUtils.getNowDate());
        return infoProjectDepartmentMapper.insertInfoProjectDepartment(infoProjectDepartment);
    }

    /**
     * 修改协同科室项目关联
     *
     * @param infoProjectDepartment 协同科室项目关联
     * @return 结果
     */
    @Override
    public int updateInfoProjectDepartment(InfoProjectDepartment infoProjectDepartment)
    {
        return infoProjectDepartmentMapper.updateInfoProjectDepartment(infoProjectDepartment);
    }

    /**
     * 批量删除协同科室项目关联
     *
     * @param ids 需要删除的协同科室项目关联主键
     *
     * @return 结果
     */
    @Override
    public int deleteInfoProjectDepartmentByIds(Long[] ids)
    {
        return infoProjectDepartmentMapper.deleteInfoProjectDepartmentByIds(ids);
    }

    /**
     * 删除协同科室项目关联信息
     *
     * @param id 协同科室项目关联主键
     * @return 结果
     */
    @Override
    public int deleteInfoProjectDepartmentById(Long id)
    {
        return infoProjectDepartmentMapper.deleteInfoProjectDepartmentById(id);
    }

    @Override
    public int saveProjectDepartment(JSONObject jsonObject) {
        List<Long> list=jsonObject.getJSONArray("projectIds").toJavaList(Long.class);
        String departmentId=jsonObject.getString("departmentIds");
        Long userId = SecurityUtils.getUserId();
        return infoProjectDepartmentMapper.insertBatchProjectDepartment(list,departmentId,userId,new Date());
    }

    @Override
    public List<Map<String,Object>> getDepartmentProjectList(String projectName) {
        Long deptId=SecurityUtils.getDeptId();
        //Long deptId=new Long("623068");
        return infoProjectDepartmentMapper.selectDepartmentProjectList(deptId,projectName);
    }
}
